package com.kcyu.sfherp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kcyu.sfherp.dto.QueryCondition;
import com.kcyu.sfherp.entity.*;
import com.kcyu.sfherp.mapper.ms.ChmxMapper;
import com.kcyu.sfherp.mapper.ms.ChzdMapper;
import com.kcyu.sfherp.mapper.ms.OrderMxMapper;
import com.kcyu.sfherp.mapper.ms.OrderZdMapper;
import com.kcyu.sfherp.service.ChzdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChzdServiceImpl extends ServiceImpl<ChzdMapper, Chzd> implements ChzdService {

    @Autowired
    private ChzdMapper chzdMapper;

    @Autowired
    private OrderZdMapper orderZdMapper;

    @Autowired
    private ChmxMapper chmxMapper;

    @Autowired
    private OrderMxMapper orderMxMapper;


    @Override
    public List<Chzd> queryZDbyCustomName(String khname,String startTime,String endTime) {
       return chzdMapper.queryZDbyCustomNameAndDate(khname,startTime,endTime);
    }

    @Override
    public List<Chmx> queryZDDetailByDh(String dh) {
        return chzdMapper.queryZDdetailByDh(dh);
    }

    public List<CustomHistoryPrice> queryJHDetailByDh(String dh){
        return chzdMapper.queryJHdetailByDh(dh);
    }

    @Override
    public List<Chmx> queryChmx(String khname, String startTime, String endTime) {
        QueryWrapper<Chmx> wrapper = new QueryWrapper<>();
        wrapper.like("khname", khname)
                .ge("rq", startTime)
                .lt("rq", endTime)
                .orderByAsc("rq");
        return chmxMapper.selectList(wrapper);
    }

    @Override
    public List<Chzd> advanceQueryZd(List<QueryCondition> queryConditions) {
        QueryCondition queryCondition = new QueryCondition();
        QueryWrapper<Chzd> queryWrapper = queryCondition.getQueryWrapper(queryConditions, Chzd.class);
        queryWrapper.orderByDesc("rq");

        return chzdMapper.selectList(queryWrapper);
    }

    @Override
    public List<Chmx> advanceQueryChmx(List<QueryCondition> queryConditions) {
        QueryCondition queryCondition = new QueryCondition();
        QueryWrapper<Chmx> queryWrapper = queryCondition.getQueryWrapper(queryConditions, Chmx.class);
        queryWrapper.orderByDesc("rq");

        return chmxMapper.selectList(queryWrapper);
    }

    @Override
    public List<OrderZd> advanceQueryOrderZd(List<QueryCondition> queryConditions) {
        QueryCondition queryCondition = new QueryCondition();
        QueryWrapper<OrderZd> queryWrapper = queryCondition.getQueryWrapper(queryConditions, OrderZd.class);
        queryWrapper.orderByDesc("rq");

        return orderZdMapper.selectList(queryWrapper);
    }

    @Override
    public List<OrderMx> advanceQueryOrderMx(List<QueryCondition> queryConditions) {
        QueryCondition queryCondition = new QueryCondition();
        QueryWrapper<OrderMx> queryWrapper = queryCondition.getQueryWrapper(queryConditions, OrderMx.class);
        queryWrapper.orderByDesc("rq");

        return orderMxMapper.selectList(queryWrapper);
    }
}
